package com.njwb.consumer.controller;

import com.njwb.common.json.ResponseResult;
import com.njwb.common.pojo.User;
import com.njwb.consumer.remote.service.FeignRemoteUserService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.*;

@RestController
public class UserController {
    @Autowired
    private FeignRemoteUserService feignRemoteUserService;
    @PostMapping("user")
    public ResponseResult add(User user){
//        return feignRemoteUserService.add(user.getUsername(),user.getPassword());
        return feignRemoteUserService.add(user);
    }
    @DeleteMapping("user/{id}")
    public ResponseResult remove(@PathVariable("id") Integer id){
        return feignRemoteUserService.delById(id);
    }
    @PutMapping("user")
    public ResponseResult modify(User user){
        return feignRemoteUserService.modify(user.getId(),
                                  user.getUsername(),
                                  user.getPassword());
    }
    @GetMapping("user/{id}")
    public ResponseResult getById(@PathVariable("id") Integer id){
        return feignRemoteUserService.getById(id);
    }
    @GetMapping("user")
    public ResponseResult findAll(){
        return feignRemoteUserService.findAll();
    }
}
